//package com.gdziarmaga.webshop.web.utils;
//
//import javax.annotation.PostConstruct;
//import javax.faces.component.UIComponent;
//import javax.faces.context.FacesContext;
//import javax.faces.convert.Converter;
//import javax.faces.convert.FacesConverter;
//
//import org.springframework.beans.factory.annotation.Autowired;
//
//import com.gdziarmaga.webshop.author.model.Author;
//import com.gdziarmaga.webshop.author.services.AuthorManager;
//import com.gdziarmaga.webshop.utils.filtering.BaseFilter;
//import com.gdziarmaga.webshop.utils.filtering.FilterComparisonType;
//import com.gdziarmaga.webshop.utils.filtering.FilterField;
//import com.gdziarmaga.webshop.utils.springcontext.AppContext;
//
//public class AuthorConverter implements Converter {
//
//	@Autowired
//	private AuthorManager authorManager;
//
//	@PostConstruct
//	public void init() {
//		authorManager = (AuthorManager) AppContext.getApplicationContext()
//				.getBean("authorManager");
//	}
//
//	@Override
//	public Object getAsObject(FacesContext arg0, UIComponent arg1, String author) {
//		BaseFilter filter = new BaseFilter();
//		filter.addFilterField(new FilterField<String>(author.split(" ")[0],
//				"author_first_name", FilterComparisonType.EQUAL));
//		filter.addFilterField(new FilterField<String>(author.split(" ")[1],
//				"author_last_name", FilterComparisonType.EQUAL));
//		return authorManager.getAuthorByFilter(filter).get(0);
//	}
//
//	@Override
//	public String getAsString(FacesContext arg0, UIComponent arg1, Object author) {
//		return ((Author) author).getAuthor_first_name() + " "
//				+ ((Author) author).getAuthor_last_name();
//	}
//
//}
